/*
 * ConstantDescription.java
 * 
 * last update: 30.01.2010 by Vlad Badoiu
 * 
 * author:	Vlad Badoiu(vladbadoiu@gmail.com)
 *
 * Obs:
 */

package engine;

@SuppressWarnings("serial")
class ConstantDescription implements ExpressionDescription{

	Result data;

	/**
	 * useful to create a 0 constant instance
	 */
	public static ConstantDescription zeroDescription =
		createNewSignedConstantDescription(1, true, false, 2, "0");

	public static ConstantDescription xDescription =
		createNewSignedConstantDescription(1, true, false, 2, "x");

	public static ConstantDescription zDescription =
		createNewSignedConstantDescription(1, true, false, 2, "z");

	public static ConstantDescription
	createNewStringConstantDescription (String image)
	{
		//xConsole.debug("StringConstantDescription: " + image);
		BitVector b = new BitVector(image, 256, image.length() * 8);
		return new ConstantDescription(b);
	}

	public static ConstantDescription
	createNewSignedConstantDescription (int size,
			boolean signed,
			boolean sign, 
			int base,
			String image)
	{

		BitVector b = new BitVector(image, base, size, signed, sign);
		/*xConsole.debug("SignedConstantDescription :" +
                   image + " sign: " + sign + " signed: " + signed +
                   " size: " + size + ">>>" + b ); */
		return new ConstantDescription(b);
	}

	public static ConstantDescription
	createNewUnsignedConstantDescription (int size,
			int base,
			String image)
	{
		//xConsole.debug("UnignedConstantDescription :" + image); 
		BitVector b = new BitVector(image, base, size);
		return new ConstantDescription(b);
	}

	public static ConstantDescription
	createNewRealConstantDescription (String image)
	{
		//xConsole.debug("RealConstantDescription :" + image); 
		Real r = new Real(image);
		return new ConstantDescription(r);
	}

	/**
	 *  not to be used: use the CreateNew...Description instead 
	 */
	private ConstantDescription(Result data){
		//xConsole.debug("new ConstantDescription; data is: "+data);
		this.data = data;
	}

	public Expression instantiate(NameSpace n)throws ParseException{
		//xConsole.debug("ConstantDescription.insantiate; data is: "+data);
		return new Constant(n, data, this); //note that data is not a per-instance object
	}

	public String toString(){
		return data.toString();
	}

	public boolean isLeftValue(){
		return false;
	}
}











